/**
 * IOS 不支持 “-” 连接日期，不能直接 new Date(“2020-05-18 21:00:00”)
 * 使用的格式应该为 “2020/05/18 21:00:00”
 * 所以var time = new Date(“2020-05-18 21:00:00”.replace(/-/g, “/”));
 * 
 * // HCCN-3969 HC Official WeChat】Paring with E-Coupon from HC WeChat Button
 */
/**
 * 保存HC公众号菜单按钮活动
 */
const saveHCOfficialWeChatMenuButtonActivty = function (activityName: any) {
  wx.setStorage({
    key: 'HCOfficialWeChatMenuButtonActivty',
    data: {
      activityName: activityName,
      jumpTime: new Date().getTime()
    }
  })
}

/**
 * 读取HC公众号菜单按钮活动
 */
const getHCOfficialWeChatMenuButtonActivty = function () {
  let showDetail = wx.getStorageSync('HCOfficialWeChatMenuButtonActivty')
  if (showDetail == undefined || showDetail == null || showDetail == '') {
    showDetail = {}
  }
  let activityName = ''
  if (showDetail.activityName != undefined) {
    let jumpTime = showDetail.jumpTime
    let currentTime = new Date().getTime()
    console.error('jumpTime', jumpTime, 'currentTime', currentTime);
    if (currentTime - jumpTime < 24 * 3600 * 1000) {
      activityName = showDetail.activityName
    } else {
      wx.removeStorageSync('HCOfficialWeChatMenuButtonActivty')
    }
  }
  return activityName;
}

export default {
  saveHCOfficialWeChatMenuButtonActivty,
  getHCOfficialWeChatMenuButtonActivty,
}